package controle;

import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;
import java.util.Observable;
import java.util.Observer;

import javax.swing.JButton;

import presentation.EtudiantDialog;

import abstraction.Cours;

/** controleur appelé lors de la modification d'un étudiant
 * 
 * @author PICOSSON
 *
 */
public class ControlJButtonEditEtudiant implements Observer, ActionListener {

	private Cours modele;
	private JButton button;
	private Frame parent;

	public ControlJButtonEditEtudiant(Frame parent, Cours modele, JButton button) {
		this.modele = modele;
		this.button = button;
		this.parent = parent;
		button.setEnabled(false);
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		EtudiantDialog etudiantDialog;
		Cours nouveauCours;
		try {
			nouveauCours = new Cours();
			etudiantDialog = new EtudiantDialog(parent, modele, nouveauCours, false);
			etudiantDialog.setVisible(true);
		} catch (SQLException e1) {
			e1.printStackTrace();
		}
		
	}

	@Override
	public void update(Observable o, Object message) {
		Integer iMessage = (Integer) message;
		if (iMessage == Cours.CHANGEMENT_ETUDIANT_COURANT) {
			if (modele.getEtudiantCourant() == null)
				button.setEnabled(false);
			else
				button.setEnabled(true);
		}
	}
}
